//
//  RadioDetailViewController.m
//  CwinCar
//
//  Created by dlios on 15/10/21.
//  Copyright © 2015年 dlios. All rights reserved.
//

#import "RadioDetailViewController.h"

@interface RadioDetailViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation RadioDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self creatHead];
    [self parseData];
}
-(void)creatHead
{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, mainScreen_Width, mainScree_Height/4.);
    //    view.backgroundColor = [UIColor blackColor];
    
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(10, mainScree_Height/18., mainScree_Height/9., mainScree_Height/9.)];
    imageV.layer.masksToBounds = YES;
    imageV.layer.cornerRadius = mainScree_Height/18.;
    [imageV sd_setImageWithURL:[NSURL URLWithString:self.model.album_imgurl]];
    [view addSubview:imageV];
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(mainScree_Height/9.+20, mainScree_Height/18., mainScreen_Width/2., 20)];
    nameLabel.font = [UIFont boldSystemFontOfSize:16.];
    nameLabel.text = self.model.album_name;
    [view addSubview:nameLabel];
    
    UILabel *subTitle = [[UILabel alloc]initWithFrame:CGRectMake(mainScree_Height/9.+20, mainScree_Height/18.+20, mainScreen_Width-mainScree_Height/9.-40, 55)];
    subTitle.font = [UIFont systemFontOfSize:14.];
    subTitle.numberOfLines = 3;
    subTitle.text = self.model.album_descrition;
    [view addSubview:subTitle];
    
    
    [self.view addSubview:view];
    
    
   
    
}
#pragma mark- 解析数据
-(void)parseData
{
    [AFNblock getdataWithString:[NSString stringWithFormat:@"http://app.api.autohome.com.cn/autov4.9.5/News/newsonewradiolist-pm2-aid%ld-p1-s50-tp0.json",self.model.album_id] block:^(id block) {
        self.radioDetailArray = [[NSMutableArray alloc]init];
        [self creatTable];
        for (NSDictionary *dic in [[block objectForKey:@"result"]objectForKey:@"list"]) {
            DetailRadioModel *model = [DetailRadioModel modelWithDictionary:dic];
            [self.radioDetailArray addObject:model];
        }
        
        
    }];
}
#pragma mark- 创建tableView
-(void)creatTable
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, mainScree_Height/4., mainScreen_Width, mainScree_Height*3./4.-108) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.bounces = NO;
    [self.view addSubview:self.tableView];
    
  
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.radioDetailArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellId = @"cell";
    RadioDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[RadioDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    DetailRadioModel *model = [self.radioDetailArray objectAtIndex:indexPath.row];
    [cell setDetailCell:model];
    return cell;
}
//点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ListonListViewController *listen = [[ListonListViewController alloc]init];
    listen.imageUrl = self.model.album_bigImgurl;
    DetailRadioModel *model =[self.radioDetailArray objectAtIndex:indexPath.row];
    listen.cid = model.program_id;
    listen.fileUrl = model.program_fileurl;
    listen.time = model.program_live_time;
    listen.title = model.program_title;
    [self presentViewController:listen animated:YES completion:^{
        
    }];
  
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
